package tree.easy;

import tree.Node;

import java.util.ArrayList;
import java.util.List;

public class NTreePreorder {

    public List<Integer> preorder(Node root) {
        List<Integer> list = new ArrayList<>();
        preorder(root, list);
        return list;
    }

    public void preorder(Node root, List<Integer> list) {
        if (null != root) {
            list.add(root.val);
            for (Node child : root.children) {
                preorder(child, list);
            }
        }

    }
}
